package com.workcell.workdata.xthings.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.lang.Assert;
import com.workcell.workdata.common.core.util.R;
import com.workcell.workdata.common.security.annotation.Inner;
import com.workcell.workdata.xthings.dto.CodeChainnumVo;
import com.workcell.workdata.xthings.dto.DeviceMonitorBindQueryVo;
import com.workcell.workdata.xthings.dto.DeviceMonitorQueryVo;
import com.workcell.workdata.xthings.dto.PageVo;
import com.workcell.workdata.xthings.service.IotMonitorReportService;
import com.workcell.workdata.xthings.service.factory.CodeBaseFactory;
import com.workcell.workdata.xthings.service.factory.HardwareRealDataFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *	数据监控中心看板
 *
 * @author guoyu
 * @date 2023-02-23 09:34:00
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/iotMonitorReport" )
@Api(value = "iotMonitorReport", tags = "数据监控中心看板")
public class IotMonitorReportController {

    private final IotMonitorReportService iotMonitorReportSvc;
    private final HardwareRealDataFactory hardwareRealDataFactory;
    private final CodeBaseFactory codeBaseFactory;

    /**
     * 硬件占比
     * @return
     */
    @Inner(value = false)
    @ApiOperation(value = "硬件占比", notes = "硬件占比")
    @GetMapping("/hardwarePercent" )
    public R getHardwarePercent() {
        return iotMonitorReportSvc.getHardwarePercent();
    }

    /*
     * 每日新增数据
     * @return
     */
    @Inner(value = false)
    @ApiOperation(value = "每日新增数据", notes = "每日新增数据")
    @GetMapping("/newHardwareData" )
    public R getNewHardwareData() {
        return iotMonitorReportSvc.getNewHardwareData();
    }

    /*
     * 设备数据
     * @return
     */
    @Inner(value = false)
    @ApiOperation(value = "设备数据", notes = "设备数据")
    @GetMapping("/hardwareData" )
    public R getHardwareData() {
        return iotMonitorReportSvc.getHardwareData();
    }

    /*
     * 设备最近12h在线/不在线数据
     * @return
     */
    @Inner(value = false)
    @ApiOperation(value = "设备最近12h在线/不在线数据", notes = "设备最近12h在线/不在线数据")
    @GetMapping("/hardwareDataAnalysis" )
    public R hardwareDataAnalysis() {
        return iotMonitorReportSvc.hardwareDataAnalysis();
    }

	@Inner(value = false)
	@ApiOperation(value = "通过设备类型获取设备运行数据", notes = "通过设备类型获取设备运行数据")
	@GetMapping("/hardwareDataNew" )
	public R hardwareDataNew(String hardwareType) {
		return iotMonitorReportSvc.hardwareDataNew(hardwareType);
	}

	@Inner(value = false)
	@ApiOperation(value = "通过设备类型获取设备最近24h在线/不在线数据", notes = "通过设备类型获取设备最近24h在线/不在线数据")
	@GetMapping("/hardwareDataAnalysisNew" )
	public R hardwareDataAnalysisNew(String hardwareType) {
		return iotMonitorReportSvc.hardwareDataAnalysisNew(hardwareType);
	}

	@ApiOperation(value = "通过设备类型获取设备采集数据", notes = "通过设备类型获取设备采集数据")
	@GetMapping("/getHardwareDataInfo" )
	public R getHardwareDataInfo(CodeChainnumVo.SelectChainNumDataVo selectChainNumDataVo) {
        Assert.notNull(selectChainNumDataVo.getStartTime(),"开始时间不能为空");
        Assert.notNull(selectChainNumDataVo.getEndTime(),"结束时间不能为空");
        Assert.isTrue(LocalDateTimeUtil.isSameDay(selectChainNumDataVo.getStartTime(),selectChainNumDataVo.getEndTime()),"开始时间-结束时间必须是同一天");
		return R.ok(hardwareRealDataFactory.getHardwareDataInfo(selectChainNumDataVo));
	}

    @ApiOperation(value = "监控中心-串口信息分页列表")
    @GetMapping("/serialDeviceMonitorInfoPage")
    public R serialDeviceInfoPage(PageVo pageVO, DeviceMonitorQueryVo deviceMonitorBindQueryVo) {
        return R.ok(iotMonitorReportSvc.serialDeviceMonitorInfoPage(pageVO, deviceMonitorBindQueryVo));
    }

    @ApiOperation(value = "监控中心-指定串口下绑定的设备分页列表")
    @GetMapping("/serialDeviceMonitorBindPage")
    public R serialDeviceMonitorBindPage(PageVo pageVO, DeviceMonitorBindQueryVo deviceMonitorQueryVo) {
        return R.ok(iotMonitorReportSvc.serialDeviceMonitorBindPage(pageVO, deviceMonitorQueryVo));
    }

	@ApiOperation(value = "监控中心-获取运行数据")
	@GetMapping("/getDeviceRunInfo")
	public R<CodeChainnumVo.SelectDeviceInfo> getDeviceRunInfo(String deviceNo,String manufacturerCode,String hardwareType) {
		return R.ok(iotMonitorReportSvc.getDeviceRunInfo(deviceNo, manufacturerCode, hardwareType));
	}

}
